package com.egg.ylt.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.pojo.CallCenterEntity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sichaoqi on 2018/10/16.
 */

public class ADA_CallCenterAdapter extends RecyclerView.Adapter<ADA_CallCenterAdapter.CallViewHolder> {

    private Context mContext;
    private List<CallCenterEntity> mList;
    private LayoutInflater mInflater;
    private OnItemClickListener mItemListener;

    public ADA_CallCenterAdapter(Context context, List<CallCenterEntity> list) {
        this.mContext = context;
        this.mList = list;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public CallViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CallViewHolder(mInflater.inflate(R.layout.item_call_recycler, parent, false));
    }

    @Override
    public void onBindViewHolder(CallViewHolder holder, int position) {
        final CallCenterEntity callCenterEntity = mList.get(position);
        holder.tvCallTitle.setText(callCenterEntity.getTitle());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mItemListener.onItemClick(callCenterEntity.getTitle(), callCenterEntity.getContent());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class CallViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_call_title)
        TextView tvCallTitle;
        public CallViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(String title, String content);
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.mItemListener = listener;
    }
}
